import React, { Component } from 'react';
import { DownloadOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import { Button, Modal } from 'antd';
import { withRouter } from 'dva/router';

import downloadFile from '@/utils/utils';

class ProDetail extends Component {
  state = {
    excelLoading: false,
  };

  // 导出
  export = () => {
    const { selectedRowKeys, downloadParams } = this.props;

    const params = selectedRowKeys.length
      ? { busiIds: selectedRowKeys, ...downloadParams }
      : { ...downloadParams };
    if (selectedRowKeys.length) {
      this.setState({
        excelLoading: true,
      });
      downloadFile(params, '/esApi/astProb/exportProb', 'POST', () => {
        this.setState({
          excelLoading: false,
        });
      });
    } else {
      Modal.confirm({
        title: `如果不选择数据，则默认导出当前列表下所有数据`,
        okText: '确认',
        icon: <QuestionCircleOutlined />,
        cancelText: '取消',
        onOk: () => {
          this.setState({
            excelLoading: true,
          });
          downloadFile(params, '/esApi/astProb/exportProb', 'POST', () => {
            this.setState({
              excelLoading: false,
            });
          });
        },
        onCancel: () => {
          this.setState({
            excelLoading: false,
          });
        },
      });
    }
  };

  render() {
    const { excelLoading } = this.state;

    return (
      <Button onClick={this.export} style={{ marginRight: 8 }} loading={excelLoading}>
        <DownloadOutlined /> 导出
      </Button>
    );
  }
}
export default withRouter(ProDetail);
